package codeRandomThoughts.Test530二叉搜索树的最小绝对差;

import codeRandomThoughts.utils.TreeNode;

public class Solution {
    public TreeNode pre;
    public int min = Integer.MAX_VALUE;

    public int getMinimumDifference(TreeNode root) {
        inorder(root);
        return min;
    }

    public void inorder(TreeNode root) {
        if (root == null) {
            return;
        }

        //左
        inorder(root.left);

        //根
        if (pre != null) {
            int tem = Math.abs(root.val - pre.val);
            if (tem < min) {
                min = tem;
            }
        }
        pre = root;

        //右
        inorder(root.right);
    }
}
